package lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 多线程测试锁ReentrantLock
 * 重入锁测试
 */
public class ReentrantLockDemo {
    ReentrantLock lock = new ReentrantLock();
    private void print() {
        lock.lock();
        try {
            //        doAdd();

            Thread.sleep(1000);
            System.out.println("==");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }finally {
            lock.unlock();
        }


    }
    private void doAdd() {
        lock.lock();
        lock.lock();
        System.out.println("doAdd...");
        lock.unlock();
        lock.unlock();
    }
    public static void main(String[] args) {
        ReentrantLockDemo reentrantLockDemo = new ReentrantLockDemo();
        for (int i=0;i<10;i++){
           new Thread(()->{
               reentrantLockDemo.print();
           }).start();
       }
    }
}
